package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.constant.MessageConstant;
import com.itheima.dao.CheckItemMapper;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

//解决老版本开启事务对外暴露接口不相符
@Service(interfaceClass = CheckItemService.class)
//@Transactional
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;

    //新增检查项
    @Override
    public Integer insertCheckItem(CheckItem checkItem) {

        Integer integer = checkItemMapper.insertCheckItem(checkItem);

        return integer;
    }

    //删除检查项
    @Override
    public Integer deleteCheckItem(Integer id) {
        if (checkItemMapper.findCount(id) > 0) {
            return -1;
        }
        //执行删除
        return checkItemMapper.deleteCheckItem(id);
    }


    /**
     * 根据id或名称或编码进行查询
     *
     * @param queryPageBean
     * @return
     * @author cc
     */
    @Override
    public PageResult findByAll(QueryPageBean queryPageBean) {
        if (null == queryPageBean) {
            return null;
        }
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());

        final String queryString = queryPageBean.getQueryString();
        final List<CheckItem> checkItemList = checkItemMapper.findByAll(queryString);
        PageInfo<CheckItem> pageInfo = new PageInfo<>(checkItemList);

        PageResult pageResult = new PageResult(pageInfo.getTotal(), checkItemList);
        return pageResult;
    }

    @Override
    public List<CheckItem> findAll() {

        return checkItemMapper.findAll();
    }

}
